package com.ricky;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 *  实验不使用SpringBoot默认的parent，使用自定义的parent
 *
 *  步骤 1.
 *  在自定义的parent中加入

 <dependencyManagement>
 <dependencies>
 <dependency>
 <!-- Import dependency management from Spring Boot -->
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-dependencies</artifactId>
 <version>2.0.1.RELEASE</version>
 <type>pom</type>
 <scope>import</scope>
 </dependency>
 </dependencies>
 </dependencyManagement>


 步骤二
 在自定义的parent中加入

 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 <version>2.0.1.RELEASE</version>
 <executions>
 <execution>
 <goals>
 <goal>repackage</goal>
 </goals>
 </execution>
 </executions>
 </plugin>

 步骤三

 在child中引入parent
 <parent>
 <groupId>SpringBootLearn</groupId>
 <artifactId>SpringBootLearn</artifactId>
 <version>1.0</version>
 </parent>

 此例中需要引入
 <!--添加额外依赖 -->
 <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 </dependencies>

 步骤四
 执行mvn package  或者在idea中点击右侧maven侧边栏中chapter03中的plugins下springboot相关选项。
 * */
//开启SpringBoot自动注入配置  等价于原来的SpringBootApplication
@EnableAutoConfiguration
//开启RestController注解  含有ResponseBody 即非页面形式
@RestController
public class SpringBootApplication {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @GetMapping("/")
    public String home(HttpServletRequest request) {
        logger.info("HelloWorld 访问成功");
        return "Hello World!";
    }

    /**
     * 开启SpringBoot服务
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class,args);
    }
}